#include "CreditsMenuState.h"

#include "Game.h"
#include "MainMenuState.h"
#include "Game.h"

CreditsMenuState* CreditsMenuState::pInstance = nullptr;
/*static*/ CreditsMenuState* CreditsMenuState::GetInstance( void )
{
	// Allocate the static pointer if necessary
	if( pInstance == nullptr )
		pInstance = new CreditsMenuState;

	// Return the singleton
	return pInstance;
}
/*static*/ void CreditsMenuState::DeleteInstance( void )
{
	delete pInstance;
	pInstance = nullptr;
}

CreditsMenuState::CreditsMenuState(void)
{
	creditsRect.top = 700;
	creditsRect.bottom = 900;
	creditsRect.left = Game::GetInstance()->GetScreenWidth() / 2 - 65;
	creditsRect.right = Game::GetInstance()->GetScreenWidth() / 2 + 50;

	BackgroundImageID = -1;
	NavMenuID = -1;
}

CreditsMenuState::~CreditsMenuState(void)
{

}



// Update
void CreditsMenuState::Update(float deltaTime)
{
	if(dI->KeyPressed(DIK_ESCAPE) || dI->JoystickButtonPressed(6) || dI->JoystickButtonPressed(7))
	{
		Game::GetInstance()->ChangeState(MainMenuState::GetInstance());
		return;
	}
	//TODO: Make credits scroll based off of deltaTime
	creditsRect.bottom -=(LONG)( 170 * deltaTime);
	creditsRect.top -= (LONG)( 170 * deltaTime);

	if(creditsRect.bottom < 0)
	{
		Game::GetInstance()->ChangeState(MainMenuState::GetInstance());
	}

}

// Render
void CreditsMenuState::Render(void) const
{
	if( NavMenuID != -1 )
	{
		//Draw the nav box
		tM->Draw(NavMenuID, 0,0);
	}

	RECT ScreenRect = {0,0,Game::GetInstance()->GetScreenWidth(),Game::GetInstance()->GetScreenHeight() };
	D3D->DrawRect(ScreenRect,D3DCOLOR_ARGB(0,0,0,255));

	D3D->DrawRect(creditsRect,D3DCOLOR_ARGB(0,0,0,255));
	D3D->DrawText(_T("Developers/Designers:\n\t\t\
					 \t     Paul Bennett\n\t\t\
					 \t     Daniel Stover\n\t\t\
					 \t     Geoffrey Harrison\n\t\t\
					 \t     Joshua Bramer\n\t\t\
					 \t     Nick Cerame\n\n\
					 Producer:\n\t\t\
					 \t    John O'Leske\n\t\t\n\
					 Associate Producer:\n\t\t\
					 \t     Sean Hathaway\n\n\
					 Artists:\n\t\t\
					 \t  Robot With A Smile\n\t\t\
					 \t     Daniel Stover\n\t\t\n\
					 Music:\n\t\t\
					 \t   Paul Bennett\n\t\t\
					 \n  Special Thanks!\n\
					 \t   Dr. Jeff Stover \n\
					 \t   Dr. Anne Stover"),creditsRect.left,creditsRect.top,D3DCOLOR_ARGB(255,255,255,255));

	//Draw the Background overlay
	if( BackgroundImageID != -1 )
	{
		if(Game::GetInstance()->GetScreenHeight() != 600 && Game::GetInstance()->GetScreenWidth() != 800)
			tM->Draw(BackgroundImageID, 0,0,0.95f,1.055f); 
	}
}

// Enter
//	- Used to initialize the game state.
void CreditsMenuState::Enter(void)
{
	GameState::Enter();

	BackgroundImageID = tM->LoadTexture("Textures\\Menu\\CreditsMenuBackground.png");
	NavMenuID = tM->LoadTexture("Textures\\Menu\\CreditsNav.png");
}

// Exit
//	- Used to clean up the game state.
void CreditsMenuState::Exit(void)
{
	GameState::Exit();
	DeleteInstance();
}